package com.cljz.makepassenger.share;

import android.app.Activity;
import android.content.Context;

import com.cljz.makepassenger.base.App;
import com.cljz.makepassenger.ui.activity.MainActivity;
import com.cljz.makepassenger.utils.ActivityManager;
import com.cljz.makepassenger.utils.T;
import com.umeng.socialize.UMShareListener;
import com.umeng.socialize.bean.SHARE_MEDIA;

import cn.droidlover.xdroidmvp.router.Router;

/**
 * Created by CLJZ on 2017/3/2.
 */
public class ShareManager implements UMShareListener {
    private Context context;

    public ShareManager(Context context) {
        this.context = context;
    }

    @Override
    public void onStart(SHARE_MEDIA share_media) {

    }

    @Override
    public void onResult(SHARE_MEDIA platform) {

        com.umeng.socialize.utils.Log.d("plat", "platform" + platform);
        if (platform.name().equals("WEIXIN_FAVORITE")) {
            shareResult(platform, "收藏成功");
        } else {
            shareResult(platform, "分享成功");
//            context.startActivity(new Intent(context, InvitationListActivity.class));
//            AppManager.getAppManager().finishOtherActivity(InvitationListActivity.class);
//            if (context instanceof InvitationFileActivity) {
//                ((InvitationFileActivity) context).finish();
//            }
            ActivityManager.getInstance().finishAfterActivity(MainActivity.class);
            Router.newIntent((Activity) App.getInstance()).to(MainActivity.class).launch();
        }
    }

    @Override
    public void onError(SHARE_MEDIA platform, Throwable t) {
        T.getInstance().showShort(platform + "" + " 分享失败");
        shareResult(platform, "分享失败");
        if (t != null) {
            com.umeng.socialize.utils.Log.d("throw", "throw:" + t.getMessage());
        }
    }

    @Override
    public void onCancel(SHARE_MEDIA platform) {
        shareResult(platform, "取消分享");
    }

    private void shareResult(SHARE_MEDIA platform, String msg) {
        if (SHARE_MEDIA.QQ.equals(platform)) {
            T.getInstance().showShort(" QQ " + msg);
        } else if (SHARE_MEDIA.QZONE.equals(platform)) {
            T.getInstance().showShort(" QQ空间 " + msg);
        } else if (SHARE_MEDIA.WEIXIN.equals(platform)) {
            T.getInstance().showShort(" 微信 " + msg);
        } else if (SHARE_MEDIA.WEIXIN_CIRCLE.equals(platform)) {
            T.getInstance().showShort(" 微信朋友圈 " + msg);
        }
    }
}
